package com.briup.jz.service.impl;

import com.briup.jz.bean.BaseUser;
import com.briup.jz.bean.BaseUserExample;
import com.briup.jz.dao.BaseUserMapper;
import com.briup.jz.service.IBaseUserService;
import com.briup.jz.utils.CustomerException;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class BaseUserServiceImpl implements IBaseUserService {

    //依赖注入
    @Resource
    private BaseUserMapper baseUserMapper;

    @Override
    public void saveOrUpdat(BaseUser baseUser) throws CustomerException {
        if ( baseUser.getId()!=null){
            //更新操作
            baseUserMapper.updateByPrimaryKey( baseUser);
        }else {
            baseUserMapper.insert(baseUser);
        }

    }

    @Override
    public List<BaseUser> query(String username) {

        //创建一个模板对象
        BaseUserExample example=new BaseUserExample();
        if (username!=null){
            //加入参数模糊查询
            example.createCriteria().andUsernameLike("%"+username+"%");
        }
        //导入参数
       return baseUserMapper.selectByExample(example);
    }

    @Override
    public void deleteById(Long id) throws CustomerException {

        baseUserMapper.deleteByPrimaryKey(id);
    }


    @Override
    public List<BaseUser> queryAll() {
        BaseUserExample example=new BaseUserExample();
      return baseUserMapper.selectByExample(example);
    }
}
